package org.example.controller;

import org.example.result.Result;
import org.example.service.PermissionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    public PermissionController(PermissionService permissionService) {
        this.permissionService = permissionService;
    }

    /**
     * 绑定默认角色
     * @param userId
     */
    @PostMapping("/bindDefaultRole")
    public Result bindDefaultRole(@RequestParam BigInteger userId) {
        return permissionService.bindDefaultRole(userId);
    }

    @GetMapping("/getUserRoleCode")
    public String getUserRoleCode(@RequestParam BigInteger userId) {
        return permissionService.getUserRoleCode(userId);
    }

    @PostMapping("/upgradeToAdmin")
    public Result upgradeToAdmin(@RequestParam BigInteger targetUserId, @RequestParam BigInteger currentUserId) {
        return permissionService.upgradeToAdmin(targetUserId,currentUserId);
    }

    @PostMapping("/downgradeToUser")
    public Result downgradeToUser(@RequestParam BigInteger targetUserId, @RequestParam BigInteger currentUserId) {
        return permissionService.downgradeToUser(targetUserId,currentUserId);
    }

    /**
     * 绑定超级管理员角色
     *
     * @param userId 用户ID
     */
    @PostMapping("/bindSuperAdminRole")
    public Result bindSuperAdminRole(@RequestParam("userId") BigInteger userId) {
        permissionService.bindSuperAdminRole(userId);
        return Result.success();
    }
}
